{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import logging\n",
    "\n",
    "logging.basicConfig(\n",
    "    filename='log.log',          # 日志文件名\n",
    "    filemode='w',               # 写入模式：'a'追加，'w'覆盖\n",
    "    level=logging.INFO,         # 记录级别\n",
    "    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',\n",
    "    datefmt='%Y-%m-%d %H:%M:%S'\n",
    ")\n",
    "\n",
    "logging.info('这是一条信息日志')\n",
    "logging.info('这是一条信息日志x2')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'id': 1, 'name': 'Alice', 'score': 90, 'passed': True},\n",
       " {'id': 2, 'name': 'Bob', 'score': 95, 'passed': True},\n",
       " {'id': 3, 'name': 'Charlie', 'score': 83, 'passed': True}]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[\n",
    "    {'id': 1, 'name': 'Alice', 'score': 90, 'passed': True},\n",
    "    {'id': 2, 'name': 'Bob', 'score': 95, 'passed': True},\n",
    "    {'id': 3, 'name': 'Charlie', 'score': 83, 'passed': True}\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'id': 1, 'name': 'Alice', 'score': 90, 'passed': True}, {'id': 2, 'name': 'Bob', 'score': 95, 'passed': True}, {'id': 3, 'name': 'Charlie', 'score': 83, 'passed': True}]\n"
     ]
    }
   ],
   "source": [
    "rows_lst = [\n",
    "    {'id': 1, 'name': 'Alice', 'score': 85},\n",
    "    {'id': 2, 'name': 'Bob', 'score': 90},\n",
    "    {'id': 3, 'name': 'Charlie', 'score': 78}\n",
    "]\n",
    "\n",
    "# 遍历并修改字典内容\n",
    "for idx, row in enumerate(rows_lst):\n",
    "    row['score'] += 5  # 给每个人加5分\n",
    "    row['passed'] = row['score'] >= 80  # 添加新字段\n",
    "    \n",
    "    # 也可以通过索引直接访问修改\n",
    "    # rows_lst[idx]['score'] += 5  # 效果相同\n",
    "\n",
    "print(rows_lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
